﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Aioms.Common;
using Aioms.Controllers;
using Aioms.Models;
using EasyQuartz;
using Furion;
using Furion.DatabaseAccessor;
using Furion.RemoteRequest.Extensions;
using Masuit.Tools;
using Quartz;
using SqlSugar;
using SqlSugar.Extensions;
using StackExchange.Profiling.Internal;

namespace Aioms.Cron
{
    //[TriggerCron("0/5 * * * * ? *")]
    [TriggerCron("0 0 1 * * ? *")]
    [DisallowConcurrentExecution]
    public class TpPlanJob : IJob
    {
        private readonly ISqlSugarClient db; // 核心对象：拥有完整的SqlSugar全部功能
        public TpPlanJob()
        {
            this.db = new SqlSugarClient(new ConnectionConfig
            {
                ConnectionString = App.Configuration["ConnectionStrings:Default"],
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute//从特性读取主键自增信息
            });
            //处理日志事务
            db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine(sql);
                Console.WriteLine(string.Join(",", pars?.Select(it => it.ParameterName + ":" + it.Value)));
                Console.WriteLine();
            };
        }
        public async Task Execute(IJobExecutionContext context)
        {
            var response = await "http://localhost:5100/api/cron/generatetpworkorder".GetAsync();
            Console.WriteLine(response);
        }
    }
}
